package com.faiz.algorithm;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class BubbleSort {

    public static int[] bubbleSort(int[] nums) {
        if (nums == null) return null;
        int l = nums.length;
        for (int i = 0; i < l - 1; i++) {
            for (int j = 0; j < l - i - 1; j++) {
                if (nums[j] > nums[j + 1]) {
                    int tmp = nums[j];
                    nums[j] = nums[j + 1];
                    nums[j + 1] = tmp;
                }
            }
        }
        return nums;
    }

    public static void main(String[] args) {
        int[] nums = {5, 8, 2, 1, 8};
        int[] sortedNums = bubbleSort(nums);
        System.out.println(Arrays.toString(sortedNums));
        List<Integer> list = new LinkedList<>();
        list.add(1);
    }
}
